/**
 * 制作者：九哥
 * 我的页面跳转
 * 时间：2019-03-01
 * 更新者：
 * */





/**
 * 引入缓存设置文件 cache.js
 * */
document.write("<script type='text/javascript' src='/h5/js/cache.js'></script>");





var type; //当前身份，1个人，2仅公司，3仅工厂，4公司含工厂
var typeCurr = 0; //身份类型，0代表自动
var myType = typeCurr; //我的主页，身份类型，0代表自动
var mySettingType = typeCurr; //我的设置，身份类型，0代表自动
var myPubType = typeCurr; //我的发布，身份类型，0代表自动
var myOrderType = typeCurr; //我的订单，身份类型，0代表自动
var preIndex = '../';

//返回我的
$("#myOrderRtn").on("click",function(){
    MC.back();return;
    //window.location.href = preIndex + 'myset.html';
    history.go(-1);
});

//返回我的
$("#staffJobRtn").on("click",function(){
    MC.back();return;
    //window.location.href = preIndex + 'myset.html';
    history.go(-1);
});

//返回我的
$("#settingRtn").on("click",function(){
    MC.back();return;
    //window.location.href = preIndex + 'myset.html';
    history.go(-1);
});

//返回我的
$("#myorderRtn").on("click",function(){
    MC.back();return;
    //window.location.href = preIndex + 'myset.html';
    history.go(-1);
});

//返回我的
$("#orderShowRtn").on("click",function(){
    MC.back();return;
    //window.location.href = preIndex + 'myset.html';
    history.go(-1);
});

//返回我的
$("#accountRtn").on("click",function(){
    MC.back();return;
    //window.location.href = preIndex + 'myset.html';
    history.go(-1);
});





/**
 * 主页菜单动态添加
 * */
function getMyMenus(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        //window.location.href = '/h5/login/login.html';
        getAppErrMsg('没有登陆！','/h5/login/login.html',1000); return;
    }
    var menus = new Array();
    var i, i2, i3, h = '', h2 = '', h3 = '';
    var type;
    if (myType==0) {
        type = userInfo.type;
    } else {
        type = myType;
    }

    if (type==1) { //个人
        menus = [
            [
                { name:'我的应聘',link:'my/job/staffJob.html' },
                
                { name:'我的钱包',link:'my/money/index.html' }
            ],
            //[
                //{ name:'我的收藏',link:'javascript:;' },
                //{ name:'我的工作',link:'my/work.html' }
            //],
            [
                //{ name:'我的账户',link:'my/account.html' },
                //{ name:'我的账户',link:'javascript:;' },
                { name:'我的设置',link:'my/setting.html' }
            ]
        ];
    } else if (type==2) { //仅公司
        menus = [
            [
                //{ name:'外发订单',link:'my/order.html' },
                { name:'我的发布',link:'my/comPub.html' },
                { name:'我的订单',link:'order/orderDocking.html' },
                { name:'我的招聘',link:'my/job/comJob.html' },
                
                { name:'我的钱包',link:'my/money/index.html' }
            ],
            //[
                //{ name:'我的收藏',link:'javascript:;' },
                //{ name:'商务合作',link:'javascript:;' },
                //{ name:'我的工作',link:'my/work.html' }
            //],
            [
                //{ name:'我的账户',link:'my/account.html' },
                //{ name:'我的账户',link:'javascript:;' },
                { name:'我的设置',link:'my/setting.html' }
            ]
        ];
    } else if (type==3) { //仅工厂
        menus = [
            [
                //{ name:'外发订单',link:'my/order.html' },
                { name:'我的发布',link:'my/comPub.html' },
                { name:'我的订单',link:'order/orderDocking.html' },
                { name:'我的招聘',link:'my/job/comJob.html' },
                
                { name:'我的钱包',link:'my/money/index.html' }
            ],
            //[
            //    { name:'我的收藏',link:'javascript:;' },
            //    { name:'商务合作',link:'javascript:;' },
            //    { name:'我的工作',link:'my/work.html' }
            //],
            [
                //{ name:'我的账户',link:'my/account.html' },
                //{ name:'我的账户',link:'javascript:;' },
                { name:'我的设置',link:'my/setting.html' }
            ]
        ];
    } else if (type==4) { //公司含工厂
        menus = [
            [
                //{ name:'外发订单',link:'my/order.html' },
                { name:'我的发布',link:'my/comPub.html' },
                { name:'我的订单',link:'order/orderDocking.html' },
                { name:'我的招聘',link:'my/job/comJob.html' },
                { name:'我的钱包',link:'my/money/index.html' },
            ],
            //[
            //    { name:'我的收藏',link:'javascript:;' },
            //    { name:'商务合作',link:'javascript:;' },
            //    { name:'我的工作',link:'my/work.html' }
            //],
            [
                //{ name:'我的账户',link:'my/account.html' },
                //{ name:'我的账户',link:'javascript:;' },
                { name:'我的设置',link:'my/setting.html' }
            ]
        ];
    } else { //错误提示
        //console.log('没有登陆！'); return;
        getAppErrMsg('没有登陆！','/h5/login/login.html',1000); return;
    }
    //菜单列表1
    for (i=0;i<menus[0].length;i++) {
        if (menus[0][i].link=='javascript:;') {
            h += '<a href="'+menus[0][i].link+'" class="aui-flex b-line" style="color:#535D72; " onclick="getErrMsg(\''+menus[0][i].name+'待挖掘\',\'\')">';
        } else {
            h += '<a href="'+menus[0][i].link+'" class="aui-flex b-line" style="color:#535D72; ">';
        }
        h +=    '<div style="height: 56px;line-height: 56px;">';
        h +=        '<div style="float: left;width:90%;margin-left:21px;">'+menus[0][i].name+'</div>';
        h +=        '<div class="arrow-right arrow-box">';
        h +=            '<b class="right"><i class="right-arrow1"></i><i class="right-arrow2"></i></b>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
        if (i<menus[0].length-1) { h += '<hr/>'; }
    }
    //菜单列表2
    for (i2=0;i2<menus[1].length;i2++) {
        if (menus[1][i2].link=='javascript:;') {
            h2 += '<a href="'+menus[1][i2].link+'" class="aui-flex b-line" style="color:#535D72; " onclick="getErrMsg(\''+menus[1][i2].name+'待挖掘\',\'\')">';
        } else {
            h2 += '<a href="'+menus[1][i2].link+'" class="aui-flex b-line" style="color:#535D72; ">';
        }
        h2 +=    '<div style="height: 56px;line-height: 56px;">';
        h2 +=        '<div style="float: left;width:90%;margin-left:21px;">'+menus[1][i2].name+'</div>';
        h2 +=        '<div class="arrow-right arrow-box">';
        h2 +=            '<b class="right"><i class="right-arrow1"></i><i class="right-arrow2"></i></b>';
        h2 +=        '</div>';
        h2 +=    '</div>';
        h2 += '</a>';
        if (i2<menus[1].length-1) { h2 += '<hr/>'; }
    }
    ////菜单列表3
    //for (i3=0;i3<menus[2].length;i3++) {
    //    if (menus[2][i3].link=='javascript:;') {
    //        h3 += '<a href="'+menus[2][i3].link+'" class="aui-flex b-line" style="color:#535D72; " onclick="getErrMsg(\''+menus[2][i3].name+'待挖掘\',\'\')">';
    //    } else {
    //        h3 += '<a href="'+menus[2][i3].link+'" class="aui-flex b-line" style="color:#535D72; ">';
    //    }
    //    h3 +=    '<div style="height: 56px;line-height: 56px;">';
    //    h3 +=        '<div style="float: left;width:90%;margin-left:21px;">'+menus[2][i3].name+'</div>';
    //    h3 +=        '<div class="arrow-right arrow-box">';
    //    h3 +=            '<b class="right"><i class="right-arrow1"></i><i class="right-arrow2"></i></b>';
    //    h3 +=        '</div>';
    //    h3 +=    '</div>';
    //    h3 += '</a>';
    //    if (i3<menus[2].length-1) { h3 += '<hr/>'; }
    //}
    $('#menu-1').html(h);
    $('#menu-2').html(h2);
    //$('#menu-3').html(h3);
}

/**
 * 我的信息菜单
 * */
function getSettingInfoMenu(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        //window.location.href = '/h5/login/login.html';
        getAppErrMsg('没有登陆！','/h5/login/login.html',1000); return;
    }
    //console.log(userInfo);
    var menus = new Array();
    var title;
    var i, h = '';
    if (mySettingType==0) {
        type = userInfo.type;
    } else {
        type = mySettingType;
    }
    if (type==1) { //个人
        title = '员工信息';
        menus = [
            //{ name:'基本信息',link:'staffBasic.html' },
            //{ name:'扩展信息',link:'staffExt.html' },
            //{ name:'个人认证',link:'staffFile.html' }
            { name:'我的个人信息',link:'/h5/login/staffList.html?type=edit' }
        ];
    } else if (type==2) { //仅公司
        title = '公司信息';
        menus = [
            //{ name:'基本信息',link:'comBasic.html' },
            //{ name:'认证',link:'comFile.html' },
            //{ name:'产品',link:'comPro.html' },
            //{ name:'产品风格',link:'comStyle.html' },
            //{ name:'产品款式数量',link:'comDesign.html' },
            //{ name:'产量产能',link:'comYield.html' },
            //{ name:'环境',link:'comEnv.html' }
            { name:'我的公司信息',link:'/h5/login/comList.html?type=edit' }
        ];
    } else if (type==3) { //仅工厂
        title = '工厂信息';
        menus = [
            //{ name:'基本信息',link:'comBasic.html' },
            //{ name:'认证',link:'comFile.html' },
            //{ name:'产品',link:'comPro.html' },
            //{ name:'设备',link:'comEquip.html' },
            //{ name:'产量产能',link:'comYield.html' },
            //{ name:'环境',link:'comEnv.html' }
            { name:'我的工厂信息',link:'/h5/login/facList.html?type=edit' }
        ];
    } else if (type==4) { //公司含工厂
        title = '公司信息';
        menus = [
            //{ name:'基本信息',link:'comBasic.html' },
            //{ name:'认证',link:'comFile.html' },
            //{ name:'产品',link:'comPro.html' },
            //{ name:'产品风格',link:'comStyle.html' },
            //{ name:'产品款式数量',link:'comDesign.html' },
            //{ name:'设备',link:'comEquip.html' },
            //{ name:'产量产能',link:'comYield.html' },
            //{ name:'环境',link:'comEnv.html' }
            { name:'我的公司信息',link:'/h5/login/comList.html?type=edit' }
        ];
    } else {
        //console.log('操作失败！'); return;
        getAppErrMsg('没有登陆！','/h5/login/login.html',1000); return;
    }
    for (i=0;i<menus.length;i++) {
        h += '<a href="'+menus[i].link+'">';
        h +=    '<div class="table-box">';
        h +=        '<div class="tableTitle">'+menus[i].name+'</div>';
        h +=        '<div class="arrow-box">';
        h +=            '<b class="right"><i class="right-arrow1"></i><i class="right-arrow2"></i></b>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
        if (i<menus.length-1) { h += '<hr>'; }
    }
    $('#info').html(h);
    $('#infoTitle').html(title);
}

/**
 * 我i的工作菜单
 * */
function getWorkMenus(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        //window.location.href = '/h5/login/login.html';
        getAppErrMsg('没有登陆！','/h5/login/login.html',1000); return;
    }
    var i, h = '';
    var menus = new Array();
    menus = [
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'原料物料'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'生产线'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'办公管理'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'库存仓储'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'工艺技工'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'设备维修'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'订单管理'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'HR人事'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'物流管理'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'财务管理'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'报表管理'
        },
        {
            img:'/h5/images/icon.png',
            link:'javascript:;',
            name:'考勤打卡'
        }
    ];
    for (i=0;i<menus.length;i++) {
        h += '<div class="ext" ';
        if (menus[i].link=='javascript:;') {
            h += 'onclick="getErrMsg(\'待接入\',\'\')"';
        } else {
            h += 'onclick="window.location.href=\''+menus[i].link+'\';"';
        }
        h += '>';
        h += '<img src="'+menus[i].img+'">';
        h += '<p>'+menus[i].name+'</p>';
        h += '</div>';
    }
    $('#myWork').html(h);
}





/**
 * 本地缓存，获取
 * */
function cacheGet(key){
    //return localStorage.getItem(key);
    return JSON.parse(localStorage.getItem(key));
}





///**
// * 错误提示框
// * */
//function getErrMsg(msg,url){
//    var h = '';
//    h += '<span>'+msg+'</span>';
//    h += '<script>';
//    h += 'setTimeout("setErrClose()",1000*3); function setErrClose(){ $("#errMsg").html("").hide(); }';
//    if (url!='') {
//        h += 'setTimeout("setJump()",1000*3); function setJump(){ window.location.href=\''+url+'\'; }';
//    }
//    h += '</script>';
//    $('#errMsg').html(h).show();
//}